<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Command-module for command memory &mdash; Dragonfly-modules v0.1 documentation</title>
    <link rel="stylesheet" href="_static/default.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
        VERSION:     '0.1',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="top" title="Dragonfly-modules v0.1 documentation" href="index.html" />
    <link rel="next" title="Command-module for taskbar and icon tray access" href="mod-_taskbar.html" />
    <link rel="prev" title="Command-module for cursor movement and editing" href="mod-_multiedit.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="mod-_taskbar.html" title="Command-module for taskbar and icon tray access"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="mod-_multiedit.html" title="Command-module for cursor movement and editing"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">Dragonfly-modules v0.1 documentation</a> &raquo;</li> 
      </ul>
    </div>  
    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  
  <div class="section" id="command-module-for-command-memory">
<h1>Command-module for <strong>command memory</strong><a class="headerlink" href="#command-module-for-command-memory" title="Permalink to this headline">¶</a></h1>
<p>This module offers voice-commands for <em>remembering</em> and <em>repeating</em>
previous recognitions.  This works just as well for <em>text</em> recognitions
(such as &#8220;hello world!&#8221;) and <em>command</em></p>
<div class="section" id="commands">
<h2>Commands<a class="headerlink" href="#commands" title="Permalink to this headline">¶</a></h2>
<p>The following voice commands are available:</p>
<dl class="docutils">
<dt>Command: <strong>&#8220;repeat [last] [&lt;n&gt;] (commands | command) [&lt;count&gt; times]&#8221;</strong></dt>
<dd>Repeats the <em>&lt;n&gt;</em> most recent recognitions.  If <em>&lt;count&gt;</em> is also
spoken, the series of recognitions is repeated that many times.</dd>
<dt>Command: <strong>&#8220;remember [last] [&lt;n&gt;] (commands | command) as &lt;name&gt;&#8221;</strong></dt>
<dd>Remembers the <em>&lt;n&gt;</em> most recent recognitions under the name <em>&lt;name&gt;</em>.
The remember of recognitions can be repeated by simply saying
<strong>&#8220;&lt;name&gt;&#8221;</strong>.</dd>
<dt>Command: <strong>&#8220;start recording &lt;name&gt;&#8221;</strong></dt>
<dd>Starts remembering recognitions and stores them under the name <em>&lt;name&gt;</em>.
The user must speak <strong>&#8220;stop recording&#8221;</strong> later.  After that all the
recognitions heard between start and stop commands can be repeated by
simply saying <strong>&#8220;&lt;name&gt;&#8221;</strong>.</dd>
<dt>Command: <strong>&#8220;stop recording&#8221;</strong></dt>
<dd>Stops remembering recognitions.</dd>
<dt>Command: <strong>&#8220;&lt;memory&gt; [&lt;count&gt; times]&#8221;</strong></dt>
<dd>Plays back the series of recognitions previously remembered under
the spoken <em>&lt;name&gt;</em>.  If <em>&lt;count&gt;</em> is also spoken, the series of
recognitions is repeated that many times.</dd>
</dl>
</div>
<div class="section" id="module-source-code">
<h2>Module source code<a class="headerlink" href="#module-source-code" title="Permalink to this headline">¶</a></h2>
<p>The most current version of this module can be downloaded from the <a class="reference external" href="http://dragonfly-modules.googlecode.com/svn/trunk/command-modules/_cmdmemory.py">repository here</a>.</p>
<div class="highlight-python"><table class="highlighttable"><tr><td class="linenos"><pre>  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193</pre></td><td class="code"><div class="highlight"><pre><span class="c">#</span>
<span class="c"># This file is a command-module for Dragonfly.</span>
<span class="c"># (c) Copyright 2008 by Christo Butcher</span>
<span class="c"># Licensed under the LGPL, see &lt;http://www.gnu.org/licenses/&gt;</span>
<span class="c">#</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Command-module for **command memory**</span>
<span class="sd">============================================================================</span>

<span class="sd">This module offers voice-commands for *remembering* and *repeating*</span>
<span class="sd">previous recognitions.  This works just as well for *text* recognitions</span>
<span class="sd">(such as &quot;hello world!&quot;) and *command*</span>


<span class="sd">Commands</span>
<span class="sd">----------------------------------------------------------------------------</span>

<span class="sd">The following voice commands are available:</span>

<span class="sd">Command: **&quot;repeat [last] [&lt;n&gt;] (commands | command) [&lt;count&gt; times]&quot;**</span>
<span class="sd">    Repeats the *&lt;n&gt;* most recent recognitions.  If *&lt;count&gt;* is also</span>
<span class="sd">    spoken, the series of recognitions is repeated that many times.</span>

<span class="sd">Command: **&quot;remember [last] [&lt;n&gt;] (commands | command) as &lt;name&gt;&quot;**</span>
<span class="sd">    Remembers the *&lt;n&gt;* most recent recognitions under the name *&lt;name&gt;*.</span>
<span class="sd">    The remember of recognitions can be repeated by simply saying</span>
<span class="sd">    **&quot;&lt;name&gt;&quot;**.</span>

<span class="sd">Command: **&quot;start recording &lt;name&gt;&quot;**</span>
<span class="sd">    Starts remembering recognitions and stores them under the name *&lt;name&gt;*.</span>
<span class="sd">    The user must speak **&quot;stop recording&quot;** later.  After that all the</span>
<span class="sd">    recognitions heard between start and stop commands can be repeated by</span>
<span class="sd">    simply saying **&quot;&lt;name&gt;&quot;**.</span>

<span class="sd">Command: **&quot;stop recording&quot;**</span>
<span class="sd">    Stops remembering recognitions.</span>

<span class="sd">Command: **&quot;&lt;memory&gt; [&lt;count&gt; times]&quot;**</span>
<span class="sd">    Plays back the series of recognitions previously remembered under</span>
<span class="sd">    the spoken *&lt;name&gt;*.  If *&lt;count&gt;* is also spoken, the series of</span>
<span class="sd">    recognitions is repeated that many times.</span>

<span class="sd">&quot;&quot;&quot;</span>

<span class="k">try</span><span class="p">:</span>
    <span class="kn">import</span> <span class="nn">pkg_resources</span>
    <span class="n">pkg_resources</span><span class="o">.</span><span class="n">require</span><span class="p">(</span><span class="s">&quot;dragonfly &gt;= 0.6.5beta1.dev-r97&quot;</span><span class="p">)</span>
<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
    <span class="k">pass</span>

<span class="kn">from</span> <span class="nn">dragonfly</span> <span class="kn">import</span> <span class="o">*</span>


<span class="c">#---------------------------------------------------------------------------</span>
<span class="c"># Set up this module&#39;s configuration.</span>

<span class="n">config</span>                       <span class="o">=</span> <span class="n">Config</span><span class="p">(</span><span class="s">&quot;command memory&quot;</span><span class="p">)</span>
<span class="n">config</span><span class="o">.</span><span class="n">lang</span>                  <span class="o">=</span> <span class="n">Section</span><span class="p">(</span><span class="s">&quot;Language section&quot;</span><span class="p">)</span>
<span class="n">config</span><span class="o">.</span><span class="n">lang</span><span class="o">.</span><span class="n">playback_last</span>    <span class="o">=</span> <span class="n">Item</span><span class="p">(</span><span class="s">&quot;(playback | repeat) [last] [&lt;n&gt;] (commands | command | recognitions) [&lt;count&gt; times]&quot;</span><span class="p">)</span>
<span class="n">config</span><span class="o">.</span><span class="n">lang</span><span class="o">.</span><span class="n">remember</span>         <span class="o">=</span> <span class="n">Item</span><span class="p">(</span><span class="s">&quot;remember [last] [&lt;n&gt;] (commands | command | recognitions) as &lt;name&gt;&quot;</span><span class="p">)</span>
<span class="n">config</span><span class="o">.</span><span class="n">lang</span><span class="o">.</span><span class="n">start_recording</span>  <span class="o">=</span> <span class="n">Item</span><span class="p">(</span><span class="s">&quot;start recording &lt;name&gt;&quot;</span><span class="p">)</span>
<span class="n">config</span><span class="o">.</span><span class="n">lang</span><span class="o">.</span><span class="n">stop_recording</span>   <span class="o">=</span> <span class="n">Item</span><span class="p">(</span><span class="s">&quot;stop recording&quot;</span><span class="p">)</span>
<span class="n">config</span><span class="o">.</span><span class="n">lang</span><span class="o">.</span><span class="n">playback_memory</span>  <span class="o">=</span> <span class="n">Item</span><span class="p">(</span><span class="s">&quot;&lt;memory&gt; [&lt;count&gt; times]&quot;</span><span class="p">)</span>
<span class="n">config</span><span class="o">.</span><span class="n">lang</span><span class="o">.</span><span class="n">recall</span>           <span class="o">=</span> <span class="n">Item</span><span class="p">(</span><span class="s">&quot;recall everything&quot;</span><span class="p">)</span>
<span class="n">config</span><span class="o">.</span><span class="n">load</span><span class="p">()</span>


<span class="c">#---------------------------------------------------------------------------</span>
<span class="c"># Create global dicts for storing command memories.</span>

<span class="c"># Dictionary for storing memories.</span>
<span class="n">memories</span>     <span class="o">=</span> <span class="n">DictList</span><span class="p">(</span><span class="s">&quot;memories&quot;</span><span class="p">)</span>
<span class="n">memories_ref</span> <span class="o">=</span> <span class="n">DictListRef</span><span class="p">(</span><span class="s">&quot;memory&quot;</span><span class="p">,</span> <span class="n">memories</span><span class="p">)</span>

<span class="c"># Recognition observer for retrieving recently heard recognitions.</span>
<span class="n">playback_history</span> <span class="o">=</span> <span class="n">PlaybackHistory</span><span class="p">()</span>
<span class="k">try</span><span class="p">:</span>
    <span class="n">playback_history</span><span class="o">.</span><span class="n">register</span><span class="p">()</span>
<span class="k">except</span> <span class="ne">Exception</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span>
    <span class="k">print</span> <span class="s">&quot;Warning, failed to register playback_history: </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">e</span>

<span class="n">record_history</span> <span class="o">=</span> <span class="n">PlaybackHistory</span><span class="p">()</span>
<span class="n">record_name</span> <span class="o">=</span> <span class="bp">None</span>


<span class="c">#---------------------------------------------------------------------------</span>
<span class="c"># Define this module&#39;s main functionality and rule.</span>

<span class="k">def</span> <span class="nf">print_history</span><span class="p">():</span>
    <span class="n">o</span> <span class="o">=</span> <span class="n">playback_history</span>
    <span class="k">print</span> <span class="p">(</span><span class="s">&quot;(</span><span class="si">%s</span><span class="s">) </span><span class="si">%s</span><span class="s">: </span><span class="si">%s</span><span class="se">\n</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="nb">id</span><span class="p">(</span><span class="n">o</span><span class="p">),</span> <span class="s">&quot;playback_history&quot;</span><span class="p">,</span> <span class="s">&quot;recall&quot;</span><span class="p">)</span> <span class="o">+</span> <span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">((</span><span class="s">&quot;    - </span><span class="si">%r</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">item</span><span class="p">,))</span> <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">o</span><span class="p">))</span>
    <span class="n">o</span> <span class="o">=</span><span class="n">record_history</span>
    <span class="k">print</span> <span class="p">(</span><span class="s">&quot;(</span><span class="si">%s</span><span class="s">) </span><span class="si">%s</span><span class="s">: </span><span class="si">%s</span><span class="se">\n</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="nb">id</span><span class="p">(</span><span class="n">o</span><span class="p">),</span> <span class="s">&quot;record_history&quot;</span><span class="p">,</span> <span class="s">&quot;recall&quot;</span><span class="p">)</span> <span class="o">+</span> <span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">((</span><span class="s">&quot;    - </span><span class="si">%r</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">item</span><span class="p">,))</span> <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">o</span><span class="p">))</span>

<span class="k">def</span> <span class="nf">playback_last</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">count</span><span class="p">):</span>
    <span class="c"># Retrieve playback-action from recognition observer.</span>
    <span class="k">if</span> <span class="n">playback_history</span> <span class="ow">and</span> <span class="n">playback_history</span><span class="o">.</span><span class="n">complete</span><span class="p">:</span>
        <span class="n">playback_history</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span>      <span class="c"># Remove playback recognition itself.</span>
    <span class="n">action</span> <span class="o">=</span> <span class="n">playback_history</span><span class="p">[</span><span class="o">-</span><span class="n">n</span><span class="p">:]</span>  <span class="c"># Retrieve last *n* recognitions.</span>
    <span class="n">action</span><span class="o">.</span><span class="n">speed</span> <span class="o">=</span> <span class="mf">10</span>               <span class="c"># Playback at 10x original speed.</span>

    <span class="c"># Playback action.</span>
    <span class="kn">import</span> <span class="nn">time</span><span class="p">;</span> <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">1</span><span class="p">)</span>
    <span class="n">playback_history</span><span class="o">.</span><span class="n">unregister</span><span class="p">()</span>   <span class="c"># Don&#39;t record playback.</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="k">for</span> <span class="n">index</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">count</span><span class="p">):</span>  <span class="c"># Playback *count* times.</span>
            <span class="n">action</span><span class="o">.</span><span class="n">execute</span><span class="p">()</span>        <span class="c"># Perform playback.</span>
    <span class="k">finally</span><span class="p">:</span>
        <span class="n">playback_history</span><span class="o">.</span><span class="n">register</span><span class="p">()</span> <span class="c"># Continue recording after playback.</span>

<span class="k">def</span> <span class="nf">remember</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
    <span class="c"># Retrieve playback-action from recognition observer and store it.</span>
    <span class="k">if</span> <span class="n">playback_history</span> <span class="ow">and</span> <span class="n">playback_history</span><span class="o">.</span><span class="n">complete</span><span class="p">:</span>
        <span class="n">playback_history</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span>      <span class="c"># Remove playback recognition itself.</span>
    <span class="n">action</span> <span class="o">=</span> <span class="n">playback_history</span><span class="p">[</span><span class="o">-</span><span class="n">n</span><span class="p">:]</span>  <span class="c"># Retrieve last *n* recognitions.</span>
    <span class="n">action</span><span class="o">.</span><span class="n">speed</span> <span class="o">=</span> <span class="mf">10</span>               <span class="c"># Playback at 10x original speed.</span>
    <span class="n">memories</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">name</span><span class="p">)]</span> <span class="o">=</span> <span class="n">action</span>    <span class="c"># Store playback action.</span>

<span class="k">def</span> <span class="nf">start_recording</span><span class="p">(</span><span class="n">name</span><span class="p">):</span>
    <span class="k">global</span> <span class="n">record_name</span>
    <span class="n">record_name</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>         <span class="c"># Remember memory name for later.</span>
    <span class="n">record_history</span><span class="o">.</span><span class="n">register</span><span class="p">()</span>       <span class="c"># Start recording with *record_history*.</span>
    <span class="k">del</span> <span class="n">record_history</span><span class="p">[:]</span>           <span class="c"># Clear record history.</span>

<span class="k">def</span> <span class="nf">stop_recording</span><span class="p">():</span>
    <span class="k">global</span> <span class="n">record_name</span>
    <span class="n">record_history</span><span class="o">.</span><span class="n">unregister</span><span class="p">()</span>     <span class="c"># Stop recording with *record_history*.</span>
    <span class="k">if</span> <span class="n">record_history</span> <span class="ow">and</span> <span class="n">record_history</span><span class="o">.</span><span class="n">complete</span><span class="p">:</span>
        <span class="n">record_history</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span>        <span class="c"># Remove playback recognition itself.</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">record_name</span><span class="p">:</span>
        <span class="k">return</span>
    <span class="n">action</span> <span class="o">=</span> <span class="n">record_history</span><span class="p">[:]</span>
    <span class="n">action</span><span class="o">.</span><span class="n">speed</span> <span class="o">=</span> <span class="mf">10</span>               <span class="c"># Playback at 10x original speed.</span>
    <span class="n">memories</span><span class="p">[</span><span class="n">record_name</span><span class="p">]</span> <span class="o">=</span> <span class="n">action</span>  <span class="c"># Store playback action.</span>
    <span class="n">record_name</span> <span class="o">=</span> <span class="bp">None</span>

<span class="k">def</span> <span class="nf">playback_memory</span><span class="p">(</span><span class="n">count</span><span class="p">,</span> <span class="n">memory</span><span class="p">):</span>
    <span class="k">if</span> <span class="n">playback_history</span> <span class="ow">and</span> <span class="n">playback_history</span><span class="o">.</span><span class="n">complete</span><span class="p">:</span>
        <span class="n">playback_history</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span>      <span class="c"># Remove playback recognition itself.</span>

    <span class="c"># Playback remembered action.</span>
    <span class="n">playback_history</span><span class="o">.</span><span class="n">unregister</span><span class="p">()</span>   <span class="c"># Don&#39;t record playback.</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="k">for</span> <span class="n">index</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">count</span><span class="p">):</span>  <span class="c"># Playback *count* times.</span>
            <span class="n">memory</span><span class="o">.</span><span class="n">execute</span><span class="p">()</span>        <span class="c"># Perform playback.</span>
    <span class="k">finally</span><span class="p">:</span>
        <span class="n">playback_history</span><span class="o">.</span><span class="n">register</span><span class="p">()</span> <span class="c"># Continue recording after playback.</span>


<span class="k">class</span> <span class="nc">PlaybackRule</span><span class="p">(</span><span class="n">MappingRule</span><span class="p">):</span>

    <span class="n">mapping</span>  <span class="o">=</span> <span class="p">{</span>  <span class="c"># Spoken form   -&gt;  -&gt;  -&gt;  action</span>
                <span class="n">config</span><span class="o">.</span><span class="n">lang</span><span class="o">.</span><span class="n">playback_last</span><span class="p">:</span>    <span class="n">Function</span><span class="p">(</span><span class="n">playback_last</span><span class="p">),</span>
                <span class="n">config</span><span class="o">.</span><span class="n">lang</span><span class="o">.</span><span class="n">start_recording</span><span class="p">:</span>  <span class="n">Function</span><span class="p">(</span><span class="n">start_recording</span><span class="p">),</span>
                <span class="n">config</span><span class="o">.</span><span class="n">lang</span><span class="o">.</span><span class="n">stop_recording</span><span class="p">:</span>   <span class="n">Function</span><span class="p">(</span><span class="n">stop_recording</span><span class="p">),</span>
                <span class="n">config</span><span class="o">.</span><span class="n">lang</span><span class="o">.</span><span class="n">remember</span><span class="p">:</span>         <span class="n">Function</span><span class="p">(</span><span class="n">remember</span><span class="p">),</span>
                <span class="n">config</span><span class="o">.</span><span class="n">lang</span><span class="o">.</span><span class="n">playback_memory</span><span class="p">:</span>  <span class="n">Function</span><span class="p">(</span><span class="n">playback_memory</span><span class="p">),</span>
                <span class="n">config</span><span class="o">.</span><span class="n">lang</span><span class="o">.</span><span class="n">recall</span><span class="p">:</span>           <span class="n">Function</span><span class="p">(</span><span class="n">print_history</span><span class="p">),</span>
               <span class="p">}</span>
    <span class="n">extras</span>   <span class="o">=</span> <span class="p">[</span>
                <span class="n">IntegerRef</span><span class="p">(</span><span class="s">&quot;n&quot;</span><span class="p">,</span> <span class="mf">1</span><span class="p">,</span> <span class="mf">100</span><span class="p">),</span>      <span class="c"># *n* designates the number</span>
                                              <span class="c">#  of recent recognitions.</span>
                <span class="n">IntegerRef</span><span class="p">(</span><span class="s">&quot;count&quot;</span><span class="p">,</span> <span class="mf">1</span><span class="p">,</span> <span class="mf">100</span><span class="p">),</span>  <span class="c"># *count* designates how</span>
                                              <span class="c">#  many times to repeat</span>
                                              <span class="c">#  playback.</span>
                <span class="n">Dictation</span><span class="p">(</span><span class="s">&quot;name&quot;</span><span class="p">),</span>            <span class="c"># *name* is used when</span>
                                              <span class="c">#   Naming new memories.</span>
                <span class="n">memories_ref</span><span class="p">,</span>                 <span class="c"># This is the list of</span>
                                              <span class="c">#  already-remembered</span>
                                              <span class="c">#  memories; its name is</span>
                                              <span class="c">#  *memory*.</span>
               <span class="p">]</span>
    <span class="n">defaults</span> <span class="o">=</span> <span class="p">{</span>
                <span class="s">&quot;n&quot;</span><span class="p">:</span> <span class="mf">1</span><span class="p">,</span>
                <span class="s">&quot;count&quot;</span><span class="p">:</span> <span class="mf">1</span><span class="p">,</span>
               <span class="p">}</span>


<span class="c">#---------------------------------------------------------------------------</span>
<span class="c"># Create and load this module&#39;s grammar.</span>

<span class="n">grammar</span> <span class="o">=</span> <span class="n">Grammar</span><span class="p">(</span><span class="s">&quot;command memory&quot;</span><span class="p">)</span>     <span class="c"># Create this module&#39;s grammar.</span>
<span class="n">grammar</span><span class="o">.</span><span class="n">add_rule</span><span class="p">(</span><span class="n">PlaybackRule</span><span class="p">())</span>        <span class="c"># Add the top-level rule.</span>
<span class="n">grammar</span><span class="o">.</span><span class="n">load</span><span class="p">()</span>                          <span class="c"># Load the grammar.</span>

<span class="c"># Unload function which will be called at unload time.</span>
<span class="k">def</span> <span class="nf">unload</span><span class="p">():</span>
    <span class="n">playback_history</span><span class="o">.</span><span class="n">unregister</span><span class="p">()</span>
    <span class="n">record_history</span><span class="o">.</span><span class="n">unregister</span><span class="p">()</span>
    <span class="k">global</span> <span class="n">grammar</span>
    <span class="k">if</span> <span class="n">grammar</span><span class="p">:</span> <span class="n">grammar</span><span class="o">.</span><span class="n">unload</span><span class="p">()</span>
    <span class="n">grammar</span> <span class="o">=</span> <span class="bp">None</span>
</pre></div>
</td></tr></table></div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="">Command-module for <strong>command memory</strong></a><ul>
<li><a class="reference external" href="#commands">Commands</a></li>
<li><a class="reference external" href="#module-source-code">Module source code</a></li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="mod-_multiedit.html" title="previous chapter">Command-module for cursor movement and <strong>editing</strong></a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="mod-_taskbar.html" title="next chapter">Command-module for <strong>taskbar</strong> and icon tray access</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="_sources/mod-_cmdmemory.txt">Show Source</a></li>
            </ul>
          <h3>Quick search</h3>
            <form class="search" action="search.html" method="get">
              <input type="text" name="q" size="18" /> <input type="submit" value="Go" />
              <input type="hidden" name="check_keywords" value="yes" />
              <input type="hidden" name="area" value="default" />
            </form>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="mod-_taskbar.html" title="Command-module for taskbar and icon tray access"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="mod-_multiedit.html" title="Command-module for cursor movement and editing"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">Dragonfly-modules v0.1 documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2008, Christo Butcher.
      Last updated on Apr 10, 2009.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.5.1.
    </div>
  </body>
</html>